package repertory.android.ericchen.androidrepertory.view;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;

import repertory.android.ericchen.androidrepertory.R;

/**
 * className:MyBottomPoupDialog
 * author: Ericchen
 * description:自定义底部弹出框
 * date: 2017/3/8 17:15
 * update: 2017/3/8
 * version:
 */
public class MyBottomPoupDialog extends BottomPopupDialog{
    private ListView itemList;
    private MyBottomPoupAdapter adapter;
    private Context mContext;
    private OnMenuItemClickListener menuItemClickListener;
    public MyBottomPoupDialog(Context context, OnDialogChangeListener listener,OnMenuItemClickListener menuListener, ArrayList<String> data,
                              boolean hasIcon,ArrayList<Integer> iconData) {
        super(context,listener);
        this.mContext = context;
        this.menuItemClickListener = menuListener;
        LayoutInflater inflater = getLayoutInflater();
        View centerView = inflater.inflate(R.layout.my_bottom_popup_dialog, null);
        addCenterView(centerView);

        itemList = (ListView)findViewById(R.id.item_list);
        adapter = new MyBottomPoupAdapter(mContext,data,hasIcon,iconData);
        itemList.setAdapter(adapter);
        itemList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                menuItemClickListener.onItemClick(i);
                dismiss();
            }
        });
    }


    public interface OnMenuItemClickListener {
        public void onItemClick(int position);
    }

    @Override
    public void show() {
        showFromBottom();
    }

    @Override
    public void dismiss() {
        dismissToBottom();
    }

}
